#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
void split(char* argv[],char* command,char* x){
    char* temp;
    int i=0;
    temp=strtok(command,x);
    while(temp){
        strcpy(argv[i],temp);
        i++;
        temp=strtok(NULL,x);
    }
    argv[i]=0;
}
int main() {
int pid;
int rtn;
int exec_errorno;
char command[256];
while (1) {
char *argv[20];
printf(">");
fgets(command, 256, stdin);
int i;
for(i=0;i<20;i++){
    argv[i]=(char*)malloc(sizeof(char)*20);
}
command[strlen(command)-1]='\0';
split(argv,command," ");
if (!strcmp(command, "quit")) {
    break;
}
// Create a child process to execute command
pid = fork();
if (pid < 0) {
    perror("Failed while calling fork");
    exit(-1);
}
else if (pid == 0) {
    exec_errorno = execvp(argv[0], argv);
    perror(command);
    exit(exec_errorno);
}
else {
    wait(&rtn);
    printf("\nValue returned from child process, rtn = %d\n", rtn);
    printf("WEXITSTATUS(rtn) = %d\n", WEXITSTATUS(rtn));
}
}
return 0;
}
